package com.atstudy.headline.web.admin.controller.contentReviews;

import com.atstudy.headline.entity.ContentReviews;
import com.atstudy.headline.entity.UserBehaviorDaily;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.ContentReviewsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;

/**
 * 内容审核记录管理控制器
 */
@RestController
@RequestMapping("/admin/contentReviews")
public class contentReviewsController {

    @Autowired
    private ContentReviewsService contentReviewsService;

    /**
     * 分页查询内容审核记录
     * @param current 当前页码
     * @param size 每页条数
     * @param contentId 内容ID（可选）
     * @param reviewerId 审核员ID（可选）
     * @param reviewStatus 审核状态（可选，1待审/2通过/3拒绝）
     * @return 分页数据
     */
    @GetMapping("/page")
    public Result<IPage<ContentReviews>> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "6") Integer size,
            @RequestParam(required = false) Integer contentId,
            @RequestParam(required = false) Integer reviewerId,
            @RequestParam(required = false) Integer reviewStatus,
            ContentReviews contentReviews) {

        // 使用新的关联查询方法
        List<ContentReviews> reviewsList = contentReviewsService.listReviewsWithRelations(
                contentId, reviewerId, reviewStatus);

        // 手动分页逻辑
        int fromIndex = (current - 1) * size;
        int toIndex = Math.min(fromIndex + size, reviewsList.size());
        List<ContentReviews> pageList = reviewsList.subList(fromIndex, toIndex);

        // 创建分页对象
        Page<ContentReviews> page = new Page<>(current, size);
        page.setRecords(pageList);
        page.setTotal(reviewsList.size());

        return Result.ok(page);
    }
}